package thread;

public class demo4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("线程正在执行！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("我先打印完1234再结束");
                    System.out.println(1);
                    System.out.println(2);
                    System.out.println(3);
                    System.out.println(4);
                    break;
                }
            }
            System.out.println("线程结束了");
        });
        t.start();
        System.out.println("3s后结束线程");
        Thread.sleep(1000);
        t.interrupt();
    }
}
